﻿// -----------------------------------------------------------------------
// <copyright file="DataAccessExceptionHandler.cs" company="EPAM Systems">
////Copyright (c) EPAM Systems, 2012. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace MBOP.Helpers.ExceptionHandling.ExceptionHandlers
{
	#region Usings

	using System;
	using System.Data;

	using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

	#endregion

	/// <summary>
	/// Data access exception handler.
	/// </summary>
	public static class DataAccessExceptionHandler
	{
		#region Constants

		/// <summary>
		/// Represents policy name of the data access.
		/// </summary>
		private const string POLICY_DATA_ACCESS = "DataAccessPolicy";

		#endregion

		/// <summary>
		/// Handles the data access exceptions. Handling depends on policies.
		/// </summary>
		/// <param name="ex">Occurred exception</param>
		/// <returns>Indicates that the exception rethrow or not.</returns>
		public static bool HandleException(DataException ex)
		{
			Exception throwingEx;

			bool rethrow = ExceptionPolicy.HandleException(ex, POLICY_DATA_ACCESS, out throwingEx);

			if (rethrow)
			{
				throw throwingEx;
			}

			return rethrow;
		}
	}
}
